home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / TextView.h < prev    next >
C/C++ Source or Header  |  1992-06-10  |  6KB  |  203 lines

  1. #ifndef TextView_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define TextView_First
  7.  
  8. #include "StaticTView.h"
  9.  
  10. class FindDialog;
  11. class TypingCommand; 
  12.  
  13. const int cMaxBatchedIns = 80; // maximum number of batched inserts
  14.  
  15. struct SelPoint {
  16.     int ch;         // char number of a selection point
  17.     int line;       // line number of a selection
  18.     Point viewp;    // position in view coordinates
  19.     bool IsEqual(const SelPoint &s2);
  20. };
  21.     
  22. void SwapSelPoints(SelPoint &p1, SelPoint &p2);
  23.  
  24. //---- TextView -------------------------------------------------------------
  25.  
  26. class TextView: public StaticTextView {
  27. friend class RangeSelector;
  28. friend class ExtendRangeSelector;
  29. public:
  30.     MetaDef(TextView);
  31.  
  32.     TextView(
  33.     EvtHandler *eh, Rectangle r, Text *t, 
  34.     bool wrap= cWordWrap,
  35.     TextViewFlags= eTextViewDefault, 
  36.     Point border= gBorder, 
  37.     TViewAlign ta= eTViewLeft,
  38.     int id= cIdNone
  39.     );  // if contentRect.extent.y is set to cVariableSize 
  40.     // extent.y is adapted to extent of largest text line
  41.  
  42.     ~TextView();
  43.     void InitNew();
  44.  
  45.     void Draw(Rectangle);
  46.     void Invert(int from, Point fp, int to, Point tp);
  47.     void HighlightSelection(HighlightState hs);
  48.     void RepairAll();
  49.  
  50.     //---- controller methods 
  51.     bool KbdFocus(bool in);
  52.     void SetKeyMap(int *map);
  53.     Command *DoLeftButtonDownCommand(Point, Token, int);
  54.     Command *DoKeyCommand(int, Token);
  55.     Command *DoCursorKeyCommand(EvtCursorDir, Token);
  56.     
  57.     //---- menu handling
  58.     static Menu *MakeMenu(int menuId);
  59.     void DoSetupMenu(class Menu *);
  60.     void SetupEditMenu(Menu *m);
  61.     void SetupSizeMenu(Menu *m);
  62.     void SetupFontMenu(Menu *m);
  63.     void SetupViewMenu(Menu *m);
  64.     void SetupCharStyleMenu(Menu *m);
  65.     void SetupFormatMenu(Menu *m);
  66.     Command *DoMenuCommand(int);
  67.     
  68.     void SetStopChars(char *stopChars);
  69.     // define in a string a list of characters that should not be
  70.     // batched in DoKeyCommand. Has to be used when DoKeyCommand
  71.     // is overridden to intercept carriage returns for instance
  72.     const char *GetStopChars();
  73.  
  74.     Command *InsertText(Text *insert); 
  75.     Command *InsertString(byte *insert, int len= -1); 
  76.  
  77.     void Enable(bool b= TRUE, bool redraw= TRUE);
  78.     GrCursor GetCursor(Point);
  79.  
  80.     //---- selection ----
  81.     void InvalidateSelection();
  82.     void SetSelection(int s= 0, int e= cMaxInt, bool redraw= TRUE);
  83.     void ClearSelection(bool redraw= TRUE);
  84.     void SetDragAndDrop(bool on);
  85.     void GetSelection(int *s, int *e);
  86.     void SelectionAsString(byte *, int max);
  87.     Text *SelectionAsText();
  88.     Rectangle SelectionRect();
  89.     Rectangle BoundingRect(int from, int to);
  90.     void RevealSelection();
  91.     bool InTextSelector()
  92.     { return inTextSelector; }
  93.     virtual void Home();
  94.     virtual void Bottom();
  95.     bool Caret();
  96.     bool AnySelection();
  97.     virtual void SelectAll(bool redraw= TRUE);
  98.     virtual void DrawCaret(Point p, int line, HighlightState);
  99.     
  100.     void ShowSelection(bool redraw= TRUE, bool show= TRUE);
  101.     bool CanShowSelection();
  102.     
  103.     //---- clipboard --------------------
  104.     bool HasSelection();
  105.     Command *PasteData(class Data*);
  106.     bool CanPaste(Data *data);
  107.  
  108.     //---- editing and screen update 
  109.     virtual void Cut();            
  110.     virtual void DelChar(int n=1);
  111.     virtual bool DeleteRequest(int from, int to);
  112.     // called before deleting the text in the range from, to
  113.     // a return value of FALSE indicates a veto, and the text will not be
  114.     // deleted 
  115.     virtual void Copy(Text *save);
  116.     virtual void Paste(Text *insert);
  117.     Text *SetText(Text *, bool scroll= cRevealTop);     // returns old text       
  118.     void SetString(byte *str, int len= -1);
  119.     CharStyle *GetCharStyle();
  120.  
  121.     void SetReadOnly(bool);
  122.     bool GetReadOnly();
  123.     
  124.     //---- searching 
  125.     // virtual FindDialog *MakeFindDialog();
  126.     virtual bool SelectRegExpr(class RegularExp *rex, bool forward= TRUE);
  127.     
  128.     //----- Command Notification
  129.     void DoneTyping();  // notify typeing command    
  130.     void TypingDeleted(TypingCommand *typing);
  131.     virtual TypingCommand *MakeTypingCommand(int cmdNo, char *name);
  132.     
  133.     //----- change notification from the text object
  134.     void DoObserve(int, int part, void*, Object *op);
  135.     bool PrintOnWhenObserving(Object *from);
  136.  
  137.     //---- activation passivation ----------------------------------------------
  138.     IStream& ReadFrom(IStream&);
  139.     
  140. protected:
  141.     class Text *scratchText;
  142.     bool updateSelection;
  143.  
  144.     //---- selection    
  145.     SelPoint start, end;            // selection range
  146.  
  147.     void NormSelection();   
  148.     // normalize selection, establisch start < end 
  149.     void PrivSetSelection(int s, int e, bool redraw= TRUE);
  150.     void PrivSetSelection(SelPoint s, SelPoint e, bool redraw= TRUE);
  151.     void Init();
  152.     bool Writeable();
  153.     virtual int CursorPos(int ch, int line, EvtCursorDir d, Point);
  154.  
  155. private:
  156.     bool inTextSelector;
  157.     bool enabled, active;
  158.     char *stopChars; // these characters wont be batched during DoKeyCommand              // if DoKeyCommand is overriden
  159.     TypingCommand *typing; // current typeing command object
  160.     FindDialog *findChange;
  161.  
  162. };
  163.  
  164. //---- inlines -----------------------------------------------------------------
  165.  
  166. inline bool SelPoint::IsEqual(const SelPoint &s2)
  167.     return (bool) (ch == s2.ch); 
  168. }
  169.  
  170. inline bool TextView::Caret()
  171.     return (bool) (start.ch == end.ch); 
  172. }
  173.  
  174. inline bool TextView::AnySelection()
  175.     return (bool) (start.ch != -1); 
  176. }
  177.  
  178. inline bool TextView::CanShowSelection()
  179.     return enabled && !gPrinting; 
  180. }
  181.     
  182. inline void TextView::GetSelection(int *s, int *e)
  183.     *s = start.ch; 
  184.     *e = end.ch; 
  185. }
  186.     
  187. inline const char *TextView::GetStopChars()
  188.     return stopChars; 
  189. }
  190.  
  191. inline bool TextView::Writeable()
  192.     return (bool) (!TestFlag(eTextViewReadOnly) && Enabled()); 
  193. }
  194.  
  195. #endif     
  196.